/**
 * $RCSfile$
 * $Revision$
 * $Date$
 * $Source$
 * $Author$
 */
package pl.edu.agh.loganalizator.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Label;

import javax.swing.Box;
import javax.swing.JComponent;
import javax.swing.JPanel;

public class RulePanelView extends JPanel {
  private static final long serialVersionUID = 240L;

  private final Box subPanel = Box.createVerticalBox();

  private final float horizontalAlign;

  private final int vgap;

  public RulePanelView() {
    this(5, LEFT_ALIGNMENT);
  }

  public RulePanelView(Color bkg) {
    this();
    subPanel.setBackground(bkg);
    this.setBackground(bkg);
  }

  public RulePanelView(int vgap, float horizontalAlign) {
    super(new BorderLayout());
    add(subPanel, BorderLayout.NORTH);
    this.vgap = vgap;
    this.horizontalAlign = horizontalAlign;
  }

  /**
   * {@inheritDoc}
   */
  public Component add(Component c) {
    // This won't work right if we remove components. But we don't, so I'm
    // not going to worry about it right now.
    if (vgap > 0 && subPanel.getComponentCount() > 0) {
      subPanel.add(Box.createVerticalStrut(vgap));
    }

    if (c instanceof JComponent) {
      ((JComponent)c).setAlignmentX(horizontalAlign);
    }

    return subPanel.add(c);
  }

}
